import React, {Component, PropTypes} from 'react';
import Signals from 'signals';
import styles from './Main.less';
import DicEditListContainer from '../Table/DicEditListContainer';
import DicItemEditListContainer from '../Table/DicItemEditListContainer';
import {getItems} from "../../services/dictionaryServer";


class DictionaryMainContainer extends React.Component {
  constructor(props) {
    super(props);
    //signals事件
    this.signal = new Signals.Signal();
    this.state = {};
  }

  componentWillMount() {
    this.signal.add(function (dic) {
      getItems(dic.id).then(function (json) {
        this.refs.itemlist.setState({
          dicId: dic.id,
          dicName: dic.name,
          dataFilter: json,
          dataSource: json
        });
      }.bind(this));
    }.bind(this));
  }

  componentWillUnmount() {
    this.signal.removeAll();
  }

  render() {
    return (
      <div className={styles.content}>
        <div className={styles.dic_lside}>
          <DicEditListContainer signal={this.signal} ref="diclist"/>
        </div>
        <div className={styles.dic_rside}>
          <DicItemEditListContainer ref="itemlist"/>
        </div>
      </div>
    );
  }
}

export default DictionaryMainContainer;
